home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CDsupport / HappyENV / Source / MountENV.asm < prev    next >
Assembly Source File  |  1997-06-12  |  4KB  |  195 lines

  1. *****************************************
  2. *        MountENV        *
  3. *    Mount tool for HappyENV-Handler    *
  4. *          1.0  05.06.97        *
  5. *****************************************
  6.  
  7. ; MountENV is Public Domain
  8.  
  9. ;Can be started from WB and CLI
  10. ;Tabsize=8
  11.  
  12.  
  13. pr_CLI        = 172
  14. pr_MsgPort    = 92
  15. pr_CurrentDir    = 152
  16. sm_NumArgs    = 28
  17. sm_ArgList    = 36
  18.  
  19. dn_Next        = 0
  20. dn_Type        = 4
  21. dn_Task        = 8
  22. dn_Lock        = 12
  23. dn_Handler    = 16
  24. dn_StackSize    = 20
  25. dn_Priority    = 24
  26. dn_Startup    = 28
  27. dn_SegList    = 32
  28. dn_GlobalVec    = 36
  29. dn_Name        = 40
  30. dn_SIZEOF    = 44
  31.  
  32. ACCESS_READ    = -2
  33.  
  34. _LVOAllocMem    = -198
  35. _LVOFindTask    = -294
  36. _LVOWaitPort    = -384
  37. _LVOGetMsg    = -372
  38. _LVOReplyMsg    = -378
  39. _LVOOpenLibrary    = -552
  40. _LVOCloseLibrary = -414
  41. _LVOForbid    = -132
  42. _LVOLock    = -84
  43. _LVOUnLock    = -90
  44. _LVOReadArgs    = -798
  45. _LVOFreeArgs    = -858
  46. _LVOAddDosNode    = -150
  47.  
  48.  
  49.  
  50. ;init place for needed structures on stack
  51. start    clr.l    -(sp)            ;get place on stack
  52.     clr.l    -(sp)
  53.     clr.l    -(sp)
  54.     clr.l    -(sp)
  55.     moveq    #20,d5            ;set return-code to FAIL
  56.     move.l    4.w,a6            ;exec-base to a6
  57.     sub.l    a1,a1
  58.     jsr    _LVOFindTask(a6)    ;find this task
  59.     move.l    d0,a4            ;a4=this task
  60.  
  61. ;check for WB or CLI start
  62.     tst.l    pr_CLI(a4)
  63.     bne.s    CLI
  64.     lea    pr_MsgPort(a4),a0    ;it was WB-start
  65.     jsr    _LVOWaitPort(a6)
  66.     lea    pr_MsgPort(a4),a0
  67.     jsr    _LVOGetMsg(a6)
  68.     move.l    d0,d2            ;d2=message from WB
  69.     jsr    _LVOForbid(a6)        ;must be in forbid-state
  70.     move.l    d2,a1
  71.     jmp    _LVOReplyMsg(a6)    ;THE END ! from WB, done nothing
  72.  
  73.  
  74. CLI    moveq    #dn_SIZEOF,d0        ;get mem for device node
  75.     move.l    #1<<16!1,d1        ;CLEAR and PUBLIC
  76.     jsr    _LVOAllocMem(a6)
  77.     tst.l    d0
  78.     beq    Ende2
  79.     move.l    d0,a2            ;a2=device node
  80.  
  81.     lea    handler(pc),a1        ;init device node
  82.     bsr    CopyBSTR
  83.     beq    Ende2
  84.     move.l    d0,dn_Handler(a2)
  85.     move.l    #2000,dn_StackSize(a2)    ;should be more than enough
  86.     moveq    #5,d0
  87.     move.l    d0,dn_Priority(a2)    ;priority=5
  88.     moveq    #-1,d0            ;no global vector
  89.     move.l    d0,dn_GlobalVec(a2)
  90.  
  91. DOS    lea    dosname(pc),a1        ;open dos.library
  92.     moveq    #30,d0
  93.     jsr    _LVOOpenLibrary(a6)
  94.     tst.l    d0
  95.     beq    Ende2
  96.     move.l    d0,a6
  97.     lea    envarc(pc),a0
  98.     move.l    a0,d1
  99.     moveq    #ACCESS_READ,d2
  100.     jsr    _LVOLock(a6)        ;make real assign out of
  101.     move.l    d0,d1            ;defer assign to ENVARC:
  102.     beq.s    Args
  103.     jsr    _LVOUnLock(a6)
  104.  
  105. Args    moveq    #0,d6            ;no startup field
  106.     lea    templat(pc),a0
  107.     move.l    a0,d1
  108.     move.l    sp,d2            ;a2=sp=arg-array
  109.     moveq    #0,d3
  110.     jsr    _LVOReadArgs(a6)    ;process argumentline
  111.     move.l    d0,d4            ;d4=RdArgs-struct
  112.     beq.s    Ende3
  113.     lea    envname(pc),a1
  114.     move.l    (sp),d0
  115.     beq.s    .A
  116.     move.l    d0,a1
  117. .A    bsr    CopyBSTR
  118.     beq.s    Ende3
  119.     move.l    d0,dn_Name(a2)
  120.     move.l    4(sp),d0
  121.     beq.s    .C
  122.     move.l    d0,a1
  123.     bsr    CopyBSTR
  124.     beq.s    .C
  125.     move.l    d0,dn_Startup(a2)
  126.  
  127. .C    move.l    d4,d1
  128.     jsr    _LVOFreeArgs(a6)    ;free RdArgs-struct, if needed
  129.     move.l    a6,a1
  130.     move.l    4.w,a6
  131.     jsr    _LVOCloseLibrary(a6)
  132.  
  133. Exp    lea    expname(pc),a1    ;open expansion.library
  134.     moveq    #30,d0
  135.     move.l    4.w,a6
  136.     jsr    _LVOOpenLibrary(a6)
  137.     tst.l    d0
  138.     beq.s    Ende2
  139.     move.l    d0,a6
  140.     move.l    a2,a0        ;add new device node
  141.     moveq    #0,d0
  142.     moveq    #0,d1
  143.     jsr    _LVOAddDosNode(a6)
  144.     tst.l    d0
  145.     beq.s    Ende3
  146.     moveq    #0,d5        ;set return code to OK
  147.  
  148. ;clean up all things used
  149. Ende3    move.l    a6,a1
  150.     move.l    4.w,a6
  151.     jsr    _LVOCloseLibrary(a6)
  152.  
  153. ;end program
  154. Ende2    lea    16(sp),sp    ;restore stack
  155.     move.l    d5,d0        ;set return-code
  156.     rts            ;THE END ! from CLI
  157.  
  158.  
  159.  
  160. * Copy CSTR to BSTR in its own memory block
  161. CopyBSTR    ;entry: a1=string
  162.         ;exit:  d0=BSTR
  163.     movem.l    d2/a0-a2/a6,-(sp)
  164.     move.l    a1,a2
  165. .test    tst.b    (a1)+
  166.     bne.s    .test
  167.     sub.l    a2,a1
  168.     move.l    a1,d2
  169.     subq.l    #1,d2
  170.     beq.s    .end
  171.     move.l    a1,d0
  172.     addq.l    #1,d0
  173.     moveq    #1,d1
  174.     move.l    4.w,a6
  175.     jsr    _LVOAllocMem(a6)
  176.     move.l    d0,a1
  177.     lsr.l    #2,d0
  178.     beq.s    .end
  179.     move.b    d2,(a1)+
  180. .loop    move.b    (a2)+,(a1)+
  181.     bne.s    .loop
  182.     tst.l    d0
  183. .end    movem.l    (sp)+,d2/a0-a2/a6
  184.     rts
  185.  
  186. version    dc.b    "$VER: MountENV 1.0 (05.06.97)",10,0
  187. templat    dc.b    "DEVNAME/K,STARTUP/F",0
  188. dosname    dc.b    "dos.library",0
  189. expname    dc.b    "expansion.library",0
  190. envarc    dc.b    "ENVARC:",0
  191. handler    dc.b    "L:HappyENV-Handler",0
  192. envname    dc.b    "ENV",0
  193.         end
  194.  
  195.